<template>
	<view class="seckill">
		<view class="top">
			<view class="title">
				<text class="name">源聚变</text>
				<view class="search">
					<input class="search-input" placeholder-style="color:#fff" type="text" value=""
						placeholder="百事可乐" />
					<image class="search-img" src="../../static/index/search.png" mode=""></image>
				</view>
			</view>
			<view class="slogan-box">
				<image class="slogan-img" src="../../static/index/miaosha.png" mode=""></image>
				<text class="slogan">精选好货 限时秒杀</text>
			</view>
		</view>
		<!-- tab切换 -->
		<view class="tabs">
			<view class="tab_name" style="width: 80rpx !important;">
				<text>今日爆款</text>
			</view>
			<view class="tab_item" :class="{cur:index === tabCur}" v-for="(item,index) in list" :key="index"
				@click="tabSelect(index)">
				{{ item.name }}
				<view :class="item.flag==true?'active':'aaa'">
					{{item.flag==true?'抢购中':'即将开始'}}
				</view>
			</view>
		</view>
		<!-- 标签页对应的内容 -->
		<block v-if="tabCur === 0">
			<view class="box" v-for="(item,index) in seckillList" :key="index">
				<image :src="item.image" mode=""></image>
				<view class="right-box">
					<text class="box-name">{{item.name}}</text>
					<view class="percentage" style="display: flex;">
						<progress :percentage='percentage' textInside=true bgColor="#FF0000" inBgColor='#FFBE8A'></progress>
						<text style="color: #999999;font-size: 28rpx;">剩余{{item.lave}}份</text>
					</view>
					<view class="box-integral">
						<text>{{item.spike_price}}积分</text>
						<text>{{item.price}}积分</text>
					</view>
					<text class="explain">历史最低兑换价</text>
					<view class="schedule" @click="jump(item)">
						<text style="font-size: 28rpx;color: #FFFFFF;">去秒杀</text>
					</view>
				</view>
			</view>
		</block>
		<block v-else-if="tabCur === 1">
			<view class="box" v-for="(item,index) in seckillList" :key="index">
				<image :src="item.image" mode=""></image>
				<view class="right-box">
					<text class="box-name">{{item.name}}</text>
					<view class="percentage" style="display: flex;">
						<progress :percentage='percentage' textInside=true bgColor="#FF0000" inBgColor='#FFBE8A'></progress>
						<text style="color: #999999;font-size: 28rpx;">剩余{{item.lave}}份</text>
					</view>
					<view class="box-integral">
						<text>{{item.price}}积分</text>
						<text>{{item.original_price}}积分</text>
					</view>
					<text class="explain">历史最低兑换价</text>
					<view class="schedule" @click="jump(item)">
						<text style="font-size: 28rpx;color: #FFFFFF;">去秒杀</text>
					</view>
				</view>
			</view>
		</block>
		<block v-else-if="tabCur === 2">
			<view class="box" v-for="(item,index) in seckillList" :key="index">
				<image :src="item.image" mode=""></image>
				<view class="right-box">
					<text class="box-name">{{item.name}}</text>
					<view class="percentage" style="display: flex;">
						<progress :percentage='percentage' textInside=true bgColor="#FF0000" inBgColor='#FFBE8A'></progress>
						<text style="color: #999999;font-size: 28rpx;">剩余{{item.lave}}份</text>
					</view>
					<view class="box-integral">
						<text>{{item.price}}积分</text>
						<text>{{item.original_price}}积分</text>
					</view>
					<text class="explain">历史最低兑换价</text>
					<view class="schedule" @click="jump(item)">
						<text style="font-size: 28rpx;color: #FFFFFF;">去秒杀</text>
					</view>
				</view>
			</view>
		</block>
		<tabbar></tabbar>
	</view>
</template>

<script>
	import {
		tabbar
	} from "../../components/tabbar/tabbar.vue"
	import progress from '../../components/ai-progress/ai-progress.vue'
	import {
		spikeList
	} from '@/service/goods.js'; //秒杀商品列表
	export default {
		components: {
			tabbar,
			progress
		},
		data() {
			return {
				percentage:'',//百分比
				tabCur: 1, // 当前tabs下标
				list: [{
						name: '10:00',
						flag: true
					},
					{
						name: '12:00',
						flag: false
					},
					{
						name: '16:00',
						flag: false
					},
				],
				seckillList: [],
				params: {
					type: 1, //默认先显示十点的
					limit: 20,
					page: 1
				},
				totalPage:0,
			}
		},
		onShow() {
			this.tabCur = 0;
			
		},
		onLoad() {
			this.seckillList = []
			this.getspikeList()
		},
		methods: {
			// tab切换
			tabSelect(index) {
				if (index == 0) { //十点
					this.seckillList = []
					this.params.type = 1
					this.getspikeList()
				}
				if (index == 1) { //十二点
					this.seckillList = []
					this.params.type = 2
					this.getspikeList()
				}
				if (index == 2) { //十六点
					this.seckillList = []
					this.params.type = 3
					this.getspikeList()
				}
				if (this.tabCur === index) return
				this.tabCur = index
			},
			//去秒
			jump(item) {
				let param = {
					id:item.id
				}
				// let url = './seckillDetail'
				let url = '/myPackageA/seckill/seckillDetail'
				this.$navTo.togo(url,param)
			},
			//获取秒杀列表
			getspikeList(isMore) {
				spikeList(this.params).then(res => {
					console.log(res.data.data, '获取秒杀列表');
					if (res.code == '200') {
						const list = res.data.data
						const total = res.data.total
						if (list.length === 0) {
							uni.showToast({
								title: '暂无内容',
								icon: 'none'
							})
							return false
						}
						list.forEach(item=>{
							let a =	(item.total_num)-(item.lave) 
							let b = (a/item.total_num)*100
							this.percentage = b
						})
						this.totalPage = Math.ceil(Number(total) / 20)
						this.seckillList = isMore ? this.seckillList.concat(list) : list
					} else {
						uni.showToast({
							title: res.msg || '获取列表失败',
							icon: 'none'
						})
					}
				})
			},
			//加载获取更多
			more() {
				if (this.params.page >= this.totalPage) {
					uni.showToast({
						title: '没有更多啦~',
						icon: 'none'
					})
					return false
				}
				this.params.page++
				this.getspikeList(true)
			},
		}
	}
</script>

<style scoped lang="less">
	.tab_name {
		font-size: 32rpx;
		font-family: Source Han Sans CN;
		font-weight: bold;
		color: #000000;
		height: 100%;
		line-height: 0;
		// display: flex;
		// justify-content: center;
		// align-items: center;
		margin: 10rpx 30rpx;

		text {
			width: 100%;
		}
	}

	/deep/.percentage {
		margin-left: 0 !important;
		font-size: 12rpx;
		font-family: Source Han Sans CN;
		font-weight: 400;
		color: #FFFFFF
	}

	/deep/.progress-container {
		width: 175rpx !important;
		height: 20rpx !important;
		margin-left: 20rpx;
	}

	.schedule {
		line-height: 24rpx;
		width: 140rpx;
		height: 58rpx;
		background-color: #FF7200;
		border-radius: 10rpx;
		position: absolute;
		bottom: 20rpx;
		right: 20rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.box:first-child {
		margin-top: 40rpx !important;
	}

	.box {
		position: relative;
		margin: 0 40rpx 40rpx;
		width: 672rpx;
		height: 182rpx;
		background: #FFFFFF;
		border-radius: 20rpx;
		display: flex;

		image {
			width: 154rpx;
			height: 156rpx;
			border-radius: 10rpx;
			margin: 12rpx;
		}

		.right-box {
			display: flex;
			flex-direction: column;
			justify-content: center;
			margin-left: 10rpx;
			line-height: 38rpx;

			.box-name {
				font-size: 32rpx;
				font-family: Source Han Sans CN;
				font-weight: 400;
				color: #2B2B2B;
			}

			.box-red {
				font-size: 20rpx;
				font-family: Source Han Sans CN;
				font-weight: 400;
				color: #FF7200;
			}

			.box-integral {
				display: flex;
				align-items: center;

				text:first-child {
					font-size: 32rpx;
					font-family: Source Han Sans CN;
					font-weight: 400;
					color: #2B2B2B;
				}

				text:last-child {
					font-size: 24rpx;
					font-family: Source Han Sans CN;
					font-weight: 400;
					color: #999999;
					text-decoration: line-through
				}
			}

			.explain {
				font-size: 24rpx;
				font-family: Source Han Sans CN;
				font-weight: 400;
				color: #999999;
			}
		}
	}

	.top {
		width: 100%;
		height: 340rpx;
		background: linear-gradient(162deg, #DD85FC 0%, #2172EB 100%);
	}

	.title {
		display: flex;
		align-items: center;
		width: 100%;
		height: 100rpx;

		.name {
			font-size: 36rpx;
			font-family: PingFang SC;
			font-weight: 400;
			color: #FFFFFF;
			padding: 0 40rpx;
			margin-top: 8%;
		}

		.search {
			position: relative;
			margin-top: 8%;

			.search-input {
				background-color: rgba(225, 225, 225, 0.22);
				border-radius: 30rpx;
				padding-left: 60rpx;
				width: 302rpx;
				height: 64rpx;
				z-index: 99;
			}

			.search-img {
				width: 32rpx;
				height: 32rpx;
				position: absolute;
				top: 16rpx;
				left: 18rpx;
			}
		}
	}

	.slogan-box {
		display: flex;
		align-items: center;
		margin: 40rpx;

		.slogan-img {
			width: 154rpx;
			height: 120rpx;
		}

		.slogan {
			font-size: 36rpx;
			color: #FFFFFF;
			font-weight: 400;
			padding-left: 12rpx;
		}
	}

	.tabs {
		position: relative;
		display: flex;
		justify-content: space-evenly;
		font-size: 36rpx;
		background-color: #FFF;
		font-weight: bold;
		color: #000000;
		margin-bottom: 40rpx;
	}

	.tab_item {
		height: 114rpx;
		line-height: 60rpx;
		flex: 1;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;

		&.cur {
			position: relative;
			color: #E7402E;
			font-weight: bold;
		}
	}

	.aaa {
		width: 146rpx;
		height: 32rpx;
		line-height: 32rpx;
		font-size: 28rpx;
		font-family: Source Han Sans CN;
		font-weight: 400;
		color: #999999;
		text-align: center;
	}

	.active {
		width: 146rpx;
		height: 32rpx;
		background: #E7402E;
		border-radius: 16rpx;
		line-height: 32rpx;
		text-align: center;
		color: #FFFFFF;
		font-size: 28rpx;
		text-align: center;
	}

	.tabs>view:first-child {
		width: 100rpx !important;
		line-height: 26px;

		.aaa {
			display: none;
		}

		.active {
			display: none;
		}
	}
</style>
